package controller;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import reservice.AgeDomain;
import reservice.AlexaUpdate;
import reservice.GetPage;
import reservice.GooglePageRank;
import reservice.Whois;

@SuppressWarnings("serial")
public class PutNetworkServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		resp.setContentType("text/plain");
		resp.setCharacterEncoding("utf-8");

		String name = Utils.fomatDomain(req.getParameter("name"));
		
		ReDomain domain = new ReDomain();
		domain.setName(name);
		
		try {
			new GetPage(domain);
		} catch (Exception e) {
			// TODO: handle exception
		}
		try {
			new GooglePageRank(domain);
		} catch (Exception e) {
			// TODO: handle exception
		}
		try {
			new AgeDomain(domain);
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		try {
			new AlexaUpdate(domain);
		} catch (Exception e) {
			// TODO: handle exception
		}
		try {
			new Whois(domain);
		} catch (Exception e) {
			// TODO: handle exception
		}

		try {
			Thread.sleep(5000);
			req.setAttribute("domain", domain);
			try {
				req.getRequestDispatcher("/put-network.jsp").forward(req, resp);
			} catch (Exception e) {
				// TODO: handle exception
			}
			
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
